package com.andreiamariei.tema6.services;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

@ManagedBean
@RequestScoped
public class SecurityService {

	public Object logout() {
		String result = "/faces/index.jsf?faces-redirect=true";
		FacesContext context = FacesContext.getCurrentInstance();
		HttpServletRequest request = (HttpServletRequest) context
				.getExternalContext().getRequest();
		try {
			request.logout();
		} catch (ServletException ex) {
			System.out.println(ex.getMessage());
			result = "/faces/login_error.jsf?faces-redirect=true";
		}
		return result;
	}
}
